<script>
	import badgeMix from '@/mixins/tabber-badge.js'
	export default {
		mixins: [badgeMix],
		data() {
			return {
				SwiperList: [],
				NavList: [],
				floorList: []
			}
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFlootrList()
		},
		methods: {
			async getSwiperList() {
				const { data } = await uni.$http.get("/home/swiperdata")
				if(data.meta.status !== 200) return uni.$showMsg()
				this.SwiperList = data.message
			},
			async getNavList() {
				const { data } = await uni.$http.get("/home/catitems")
				if(data.meta.status !== 200) return uni.$showMsg()
				this.NavList = data.message
			},
			async getFlootrList() {
				const { data } = await uni.$http.get("/home/floordata")
				if(data.meta.status !== 200) return uni.$showMsg()
				this.floorList = data.message
				this.floorList.forEach((i)=>{
					i.product_list.forEach((j)=>{
						j.url = "/subpkg/goods_list/goods_list?" + j.navigator_url.split("?")[1]
					})
				})
			},
			navClickHandler(i) {
				if(i.name === '分类') uni.switchTab({url: '/pages/cate/cate'})
				if(i.name === '秒杀拍'){}
				if(i.name === '超市购'){}
				if(i.name === '母婴品'){}
			},
			jump(){
				uni.navigateTo({url: "/subpkg/search/search"})
			}
		}
	}
</script>

<template>
	<view>
		<view class="search-box">
			<my-search @my-click="jump"></my-search>
		</view>
		<swiper indicator-dots autoplay :interval="2000" :duration="500" circular>
			<swiper-item v-for="(item,index) in SwiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?id='+ item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<view class="nav-list">
			<view @click="navClickHandler(item)" class="nav-item" v-for="(item,index) in NavList" :key="index">
				<image :src="item.image_src"></image>
			</view>
		</view>
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				<image class="title" :src="item.floor_title.image_src"></image>
				<view class="floor-img-box">
					<navigator :url="item.product_list[0].url" class="floor-left-box">
						<image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="floor-right-box">
						<navigator :url="j.url" v-if="key!==0" v-for="(j,key) in item.product_list" :key="key">
							<image :style="{width: j.image_width+'rpx'}" :src="j.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<style lang="scss">
	.search-box{
		position: sticky;
		top: 0;
		z-index: 999;
	}
	swiper-item{
		height: 330rpx;
		.swiper-item,image{
			width: 100%;
			height: 100%;
		}
	}
	.nav-list{
		display: flex;
		justify-content: space-around;
		margin: 15px 0;
		.nav-item image{
			width: 128rpx;
			height: 140rpx;
		}
	}
	.floor-list{
		.title{
			width: 100%;
			height: 60rpx;
		}
		.floor-img-box{
			display: flex;
			padding: 10px;
			.floor-right-box{
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
			}
		}
	}
	
</style>
